// components/site/button/button.js
import create from "../../../westore/utils/create"
import Api from "../../../utils/api"
import deepCopy from "../../../utils/common.js"
import Config from "../../../config"

const regeneratorRuntime = require("../../../utils/regenerator-runtime/runtime")
create({
  properties: {
    isList:{
      type: Boolean,
      value: true
    },
    theActivityData: {
      type: Array,
      value: []
    },
  },
  observers: {
    'theActivityData': function (arr) {
      const _this = this;
      if(!_this.data.isList&&arr.length>0){
        const _this = this;
        const openid = wx.getStorageSync("openid");
        if (openid == arr[0].openid) {
          _this.setData({
            isSelf: true
          })
        }
      }
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    openid:"",
    time: '2018-9-15',
    title: '活动主题文字，一行展示，多余的文字省略号......',
    like: 12,
    isSelf: false,
    comment: 23,
    dates:[],
    // 活动内容是否全部显示
    showall:[],
    showBt:[],
    releaseFocus:false,
    baseUrl: Config.baseUrl
  },

  /**
   * 组件的方法列表
   */
  methods: {
    // play(e){
    //   const _this = this;
    //   const _dataset = e.currentTarget.dataset;
    //   const videosrc = _this.data.theActivityData[_dataset.act_index].video_id[_dataset.video_index].video;
    //   wx.navigateTo({
    //     url: '/pages/player/player?video=' + videosrc,
    //   })
    // },
    // showAllButton(){
    //   const _this=this;
    //   const data = _this.data.theActivityData;
    //   let showBt = [];
    //   data.forEach(e=>{
    //     const length = e.introduction.replace(/[^\x00-\xff]/g, "01").length;
    //     length > 70 ? showBt.push(true) : showBt.push(false);
    //   })
    //   _this.setData({
    //     showBt: showBt
    //   })
    // },
    // showall(e){
    //   const _this = this;
    //   const index = e.currentTarget.dataset.i;
    //   let showlist = _this.data.showall;
    //   showlist[index] = !showlist[index];
    //   _this.setData({
    //     showall: showlist
    //   })

    // },

    // 预览图片
    lookImg: function (e) {
      const dataset = e.currentTarget.dataset
      const photo_index = dataset.photo_index
      const data = this.data.theActivityData[0].images
      const arr = data.map(item => Config.baseUrl + item)
      wx.previewImage({
        current: arr[photo_index], // 当前显示图片的http链接(string)
        urls: arr // 需要预览的图片http链接列表(array)
      })
    },
    godetail:function(e){
      const id = e.currentTarget.dataset.id;
      wx.navigateTo({
        url: '/pages/activityDetail/index?id='+id,
      })
    }
    // uploadData(){
    //   const _this=this;
    //   console.log("uploadData")
    //   _this.triggerEvent('uploadData', {}, { bubbles: true })
    // }
  }
})